package com.jackrain.nea.fc.dl.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kangcong
 * @date 2018/11/27
 **/
@Mapper
public interface ViewDLTranPlanRdcToF4Mapper {

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "selTranPlanRdcData")
    List<HashMap> selTranPlanRdcData(@Param("id") Object[] id);

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "findTranPlanItemRdcData")
    List<HashMap> findTranPlanItemRdcData(@Param("id") Long id);

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "selTranPlanRdcData1")
    List<HashMap> selTranPlanRdcData1(@Param("id") Object[] id);

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "findTranPlanItemRdcData1")
    List<HashMap> findTranPlanItemRdcData1(@Param("id") Long id);

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "findTranPlanRdcData2")
    List<HashMap> findTranPlanRdcData2(@Param("billno") Object[] billno);

    @SelectProvider(type = ViewDLTranPlanSql.class, method = "selTranPlanNoRdc")
    List<HashMap> selTranPlanNoRdc(@Param("id") Object[] id);


    class ViewDLTranPlanSql {
        public String selTranPlanNoRdc(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("FROM_BILL_NO AS FROM_BILL_NO");
                    FROM("DL_B_TRAN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("FROM_BILL_NO IS NOT NULL AND FROM_BILL_NO<>'' ");
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }

        public String selTranPlanRdcData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID AS ID, " +
                            "BILL_NO AS BILL_NO, " +
                            "BILL_DATE AS BILL_DATE, " +
                            "CP_C_ORIG_ECODE AS ORIG_NO, " +
                            "CP_C_DEST_ECODE AS DEST_NO, " +
                            "BILL_TYPE AS BILL_TYPE, " +
                            "STOP_REASON AS STOP_REASON, " +
                            "REMARK AS  REMARK, " +
                            "MODIFIERNAME AS  OPR_ECODE, " +
                            "MODIFIERENAME AS OPR_ENAME , " +
                            "MODIFIEDDATE AS  OPR_DATE, " +
                            "FROM_BILL_NO AS FROM_BILL_NO, " +
                            "VARCHAR1 AS IS_RDC_TRAN  ");
                    FROM("DL_B_TRAN_PLAN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" (VARCHAR1 = 'Y' OR VARCHAR3 = 'Y') ");
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }

        public String selTranPlanRdcData1(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID AS ID, " +
                            "BILL_NO AS BILL_NO, " +
                            "MODIFIERNAME AS  OPR_ECODE, " +
                            "MODIFIERENAME AS OPR_ENAME , " +
                            "MODIFIEDDATE AS  OPR_DATE ");
                    FROM("DL_B_TRAN_PLAN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" (VARCHAR1 = 'Y' OR VARCHAR3 = 'Y') ");
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }

        public String findTranPlanRdcData2(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("billno");
            return new SQL() {
                {
                    SELECT("ID AS ID, " +
                            "BILL_NO AS BILL_NO, " +
                            "MODIFIERNAME AS  OPR_ECODE, " +
                            "MODIFIERENAME AS OPR_ENAME , " +
                            "MODIFIEDDATE AS  OPR_DATE ");
                    FROM("DL_B_TRAN_PLAN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" (VARCHAR1 = 'Y' OR VARCHAR3 = 'Y') ");
                    WHERE("BILL_NO IN (" + sb.toString() + ")");
                }
            }.toString();
        }

        public String findTranPlanItemRdcData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_SKU_ECODE AS  PS_C_SKU_ECODE, " +
                            "QTY_EXEC_PLAN AS QTY_EXEC_PLAN , " +
                            "QTY_EXEC AS QTY_EXEC , " +
                            "QTY_OUT AS  QTY_OUT  ");
                    FROM("DL_B_TRAN_PLAN_ITEM");
                    WHERE("DL_B_TRAN_PLAN_ID =" + id);
                }
            }.toString();
        }

        public String findTranPlanItemRdcData1(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_SKU_ECODE AS SKU, " +
                            "QTY_EXEC_PLAN AS QTY , " +
                            "QTY_EXEC AS USERDEFINE1 , " +
                            "QTY_OUT AS  USERDEFINE2 ");
                    FROM("DL_B_TRAN_PLAN_ITEM");
                    WHERE("DL_B_TRAN_PLAN_ID =" + id);
                }
            }.toString();
        }


    }


}
